package cn.tedu._09security.service;

import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

public class UserDetailServiceImpl implements UserDetailsService {

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        //User.withUsername()静态方法:构建UserDetails对象;
        //{noop}:明文,生产环境中不能使用,生产黄静中的.password("")是从数据库中获取的密码;
        //.authorities(""):生产环境中是从数据库中查出的该用户的权限;
        //.build():构建UserDetailes对象;
        return User.withUsername("user")
                .password("{noop}123456") //SELECT password FROM user WHERE username=?
                .authorities("sys:private:view", "sys:private:edit") //SELECT privileges FROM user WHERE username=?
                .build();
    }
}
